let disp = require("../../../../utils/broadcast");
var app = getApp()
var time1 = null
const recorderManager = wx.getRecorderManager();


Page({
  data: {
    recordState: false, //录音状态
    content: '', //内容
    upload_picture_list: [],
    typedate: 0,
    username: {
      your: "",
    },
    shouwtab: false,
    show: !0,
    hide: !1,
    xing: 0,
    evaluate: true,
    figure: 0, // 0 患者     1 医生
    dex: "", //1 处方  ！1不是
    imgs: [],
    suc: "",
    list: [],
    play_show: true, //播放
    thtime: '00:00', //录音时长
    txt_show: true,
  },
  // 转文字
  bindzhuan(e) {
    console.log(e)
    var that = this
    var id = e.currentTarget.dataset.id
    var index = e.currentTarget.dataset.index
    var list = that.data.list
    console.log("转文字", id)
    list[index].txt_show = false
    var key_words = that.data.key_words
    if (key_words == 'tuwenwenzhen') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.shibie',
        data: {
          id: id
        },
        success: function (res) {
          console.log("文字内容", res)
          list[index].context = res.data.result[0]
          that.setData({
            list: list
          })
          console.log("文字内容", that.data.list)
        }
      })
    } else {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.shibiewz',
        data: {
          id: id
        },
        success: function (res) {
          console.log("文字内容", res)
          list[index].context = res.data.result[0]
          that.setData({
            list: list
          })
          console.log("文字内容", that.data.list)
        }
      })
    }

  },


  /*** 提示*/
  tip: function (msg) {
    wx.showModal({
      title: '提示',
      content: msg,
      showCancel: false
    })
  },
  handleRecordStart: function (e) {
    console.log("开始录音", e)
    this.setData({
      is_clock: true, //长按时应设置为true，为可发送状态
      startPoint: e.touches[0], //记录触摸点的坐标信息
    })
    //设置录音参数
    const options = {
      duration: 10000,
      sampleRate: 16000,
      numberOfChannels: 1,
      encodeBitRate: 48000,
      format: 'mp3'
    }
    recorderManager.start(options); //开始录音
    wx.showToast({
      title: '录音中',
      icon: 'none',
    })
  },
  handleRecordStop: function (e) {
    console.log(app)
    var uniacid = app.siteInfo.uniacid
    recorderManager.stop() //结束录音
    //此时先判断是否需要发送录音
    if (this.data.is_clock == true) {
      //对停止录音进行监控
      var that = this
      recorderManager.onStop((res) => {
        console.log(res)
        this.setData({
          src: res.tempFilePath
        })
        var time = res.duration
        //对录音时长进行判断，少于2s的不进行发送，并做出提示
        if (res.duration < 2000) {
          wx.showToast({
            title: '录音时间太短，请长按录音',
            icon: 'none',
            duration: 1000
          })
        } else {
          var m, s;
          m = Math.floor(time / 1000 / 60 % 60);
          s = Math.floor(time / 1000 % 60);
          if (m < 10) {
            m = '0' + m
          }
          if (s < 10) {
            s = '0' + s
          }
          this.setData({
            thtime: m + ':' + s,
            endtime: time
          })
          // that.tip("录音完成！")
          //进行语音发送
          const {
            tempFilePath
          } = res;
          //上传录制的音频

          wx.uploadFile({
            url: this.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadvideo&m=hyb_yl',
            filePath: tempFilePath,
            name: 'upfile',
            success: function (res) {
              var mp3 = res.data
              var id = app.siteInfo.id
              var zid = app.siteInfo.zid
              var key_words = app.siteInfo.key_words
              if (key_words == 'tuwenwenzhen') {
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.addzhuiwen',
                  data: {
                    zid: zid,
                    id: id,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    //是否提醒患者查看消息提醒
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words
                      },
                      success: function (res) {
                        console.log(res)
                      }
                    })
                  }
                })
              }
              if (key_words == 'dianhuajizhen' || key_words == 'shipinwenzhen' || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.addtelzhuiwen',
                  data: {
                    zid: zid,
                    id: id,
                    key_words: key_words,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    //是否提醒患者查看消息提醒
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words
                      },
                      success: function (res) {
                        //console.log(res)
                      }
                    })
                  }
                })
              }
              if (key_words == 'yuanchengkaifang') {
                var back_orser = that.data.back_orser
                app.util.request({
                  'url': 'entry/wxapp/user.addcfzhuiwen',
                  data: {
                    zid: zid,
                    keywords: key_words,
                    role: 1,
                    orders: back_orser,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    //console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words,
                        zid: zid
                      },
                      success: function (res) {
                        //console.log(res)
                      }
                    })
                  }
                })
              }
              if (key_words == 'yuanchengguahao') {
                var back_orser = that.data.back_orser
                app.util.request({
                  'url': 'entry/wxapp/zhuanjia.addguahaozhuiwen',
                  data: {
                    val: val,
                    zid: zid,
                    id: id,
                    key_words: key_words,
                    mp3: mp3,
                    thtime: that.data.endtime
                  },
                  success: function (res) {
                    console.log(res)
                    that.getOrderlist()
                    that.setData({
                      shouwtab: false
                    })
                    //是否提醒患者查看消息提醒
                    app.util.request({
                      'url': 'entry/wxapp/zhuanjia.getmbtxing',
                      data: {
                        id: id,
                        val: '一条语音信息',
                        near: key_words
                      },
                      success: function (res) {
                        //console.log(res)
                      }
                    })
                  }
                })
              }
            }
          })
        }
      })
    }
  },

  /*** 播放录音*/
  playRecord: function (e) {
    var that = this;
    var src = e.currentTarget.dataset.src
    var thtime = e.currentTarget.dataset.thtime
    var index = e.currentTarget.dataset.index
    var list = that.data.list
    if (src == '' || src == undefined) {
      that.tip("请先录音！")
      return;
    } else {
      that.innerAudioContext.src = e.currentTarget.dataset.src;
      that.innerAudioContext.play()

      list[index].play_show = false
      that.setData({
        list: list
      })
    }
    setInterval(function () {
      list[index].play_show = true
      that.setData({
        list: list
      })
      clearInterval()
    }, thtime)
  },

  //查看详情  
  lookdetail() {
    wx.navigateTo({
      url: '/hyb_yl/zhuanjiasubpages/pages/zhifuend/zhifuend?txt=yes',
    })
  },
  //立即购买   
  atbuy() {
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/chufangjianyi/chufangjianyi',
    })
  },
  //图片预览
  lookimg(e) {
    let url = e.currentTarget.dataset.img
    let lists = e.currentTarget.dataset.url
    var index = e.currentTarget.dataset.index
    //console.log(url, lists, index)

    let that = this;
    let src = e.currentTarget.dataset.img;
    wx.previewImage({
      current: src, // 当前显示图片的http链接
      urls: [src] // =============重点重点=============
    })
    // wx.previewImage({
    //   current: url,
    //   urls: lists[index].sthumb,
    // })
  },
  //关闭追问
  closezhuiwen() {
    this.setData({
      shouwtab: false
    })
  },
  //提交追问
  submitformzw(e) {
    var that = this;
    var val = e.detail.value.zhuiwen;
    var upload_picture_list = that.data.upload_picture_list
    var id = that.data.id
    var zid = that.data.zid
    var typedate = that.data.typedate
    var key_words = that.data.key_words
    var arr = {
      'text': val,
      'typedate': typedate,
      'upload_picture_list': upload_picture_list,
    }
    if (key_words == 'tuwenwenzhen') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.addzhuiwen',
        data: {
          arr: arr,
          val: val,
          zid: zid,
          id: id
        },
        success: function (res) {
          //console.log(res)
          that.getOrderlist()
          that.setData({
            shouwtab: false,
            upload_picture_list:[]
          })
          //是否提醒患者查看消息提醒
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getmbtxing',
            data: {
              id: id,
              val: val,
              near: key_words
            },
            success: function (res) {
              console.log(res)
            }
          })
        }
      })
    }
    if (key_words == 'dianhuajizhen' || key_words == 'shipinwenzhen' || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.addtelzhuiwen',
        data: {
          arr: arr,
          val: val,
          zid: zid,
          id: id,
          key_words: key_words
        },
        success: function (res) {
          console.log(res)
          that.getOrderlist()
          that.setData({
            shouwtab: false,
            upload_picture_list:[]
          })
          //是否提醒患者查看消息提醒
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getmbtxing',
            data: {
              id: id,
              val: val,
              near: key_words
            },
            success: function (res) {
              //console.log(res)
            }
          })
        }
      })
    }
    if (key_words == 'yuanchengkaifang') {
      var back_orser = that.data.back_orser
      var arr = {
        'text': val,
        'text2': '',
        'timleng': '',
        'typedate': typedate,
        'upload_picture_list': upload_picture_list,
      }
      app.util.request({
        'url': 'entry/wxapp/user.addcfzhuiwen',
        data: {
          arr: arr,
          zid: zid,
          keywords: key_words,
          role: 1,
          orders: back_orser
        },
        success: function (res) {
          //console.log(res)
          that.getOrderlist()
          that.setData({
            shouwtab: false,
            upload_picture_list:[]
          })
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getmbtxing',
            data: {
              id: id,
              val: val,
              near: key_words,
              zid: zid
            },
            success: function (res) {
              //console.log(res)
            }
          })
        }
      })
    }
    if (key_words == 'yuanchengguahao') {
      var back_orser = that.data.back_orser
      var arr = {
        'text': val,
        'text2': '',
        'timleng': '',
        'typedate': typedate,
        'upload_picture_list': upload_picture_list,
      }
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.addguahaozhuiwen',
        data: {
          arr: arr,
          val: val,
          zid: zid,
          id: id,
          key_words: key_words
        },
        success: function (res) {
          console.log(res)
          that.getOrderlist()
          that.setData({
            shouwtab: false,
            upload_picture_list:[]
          })
          //是否提醒患者查看消息提醒
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getmbtxing',
            data: {
              id: id,
              val: val,
              near: key_words
            },
            success: function (res) {
              //console.log(res)
            }
          })
        }
      })
    }
  },
  //图片上传
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              //console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  // 删除图片
  clearImg: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.ind;
    //console.log(index);
    var nowList = []; //新数据
    var imglis = that.data.upload_picture_list; //原数据
    imglis.splice(index, 1);
    that.setData({
      upload_picture_list: imglis
    })
  },
  // 图片预览
  previewImage: function (e) {
    var current = e.target.dataset.src
    wx.previewImage({
      current: current,
      urls: this.data.upload_picture_list
    })
  },
  // 关闭评价
  closeevaluate() {
    this.setData({
      evaluate: false
    })
  },
  // 评分
  xingclick(e) {
    let num = this.data.xing
    if (e.currentTarget.dataset.type == 'a') {
      this.setData({
        xing: e.currentTarget.dataset.num
      })
    } else {
      this.setData({
        xing: e.currentTarget.dataset.num + num
      })
    }
  },
  // 发布提问
  submitform(e) {
    let vals = e.detail.value.liuyan;
  },
  // options = 系统传入的 url 参数
  onLoad(options) {

    var that = this
    var id = options.id
    var zid = options.zid
    var typedate = options.typedate
    var key_words = options.key_words
    var suc = options.suc;
    if (suc != '' || suc != undefined) {
      that.setData({
        suc: suc
      })
    }
    app.util.request({
      'url': 'entry/wxapp/url',
      success: function (res) {
        var url = res.data
        that.setData({
          url: url
        })
      }
    })
    var overtime = parseInt(options.overtime * 1000)
    var openid = options.openid
    var ifpay = options.ifpay
    var date1 = new Date(overtime)
    var docindex = options.docindex
    if (options.j_id) {
      var j_id = options.j_id
      app.util.request({
        'url': 'entry/wxapp/user.detail',
        data: {
          j_id: j_id
        },
        success: function (res) {
          console.log(res)
          that.setData({
            usedetail: res.data
          })
        }
      })
      that.setData({
        j_id: options.j_id
      })
    }
    if (options.back_orser) {
      var back_orser = options.back_orser
      var openid = options.openid
      that.setData({
        back_orser: back_orser,
        openid: openid
      })
    }

    //查询所有上传的报告
    app.util.request({
      'url': 'entry/wxapp/user.tijianorder',
      data: {
        id: options.id,
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        console.log(res)
        that.setData({
          bglist: res.data
        })
      }

    })
    app.siteInfo.id = options.id
    app.siteInfo.zid = options.zid
    app.siteInfo.key_words = options.key_words
    that.setData({
      id: id,
      zid: zid,
      typedate: typedate,
      key_words: key_words,
      ifpay: ifpay,
      docindex: docindex
    })
    that.getuserone()
    that.getOrderlist()
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        //console.log(res)
        that.setData({
          url: res.data,
        })
      }
    })
    that.innerAudioContext = wx.createInnerAudioContext();
  },
  onShow: function (e) {
    var that = this
    var back_orser = that.data.back_orser
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.chufangcont',
      data: {
        back_orser: back_orser,
        c_id: 0
      },
      success: function (res) {
        console.log(res)
        that.setData({
          cfdata: res.data
        })
      }
    })
  },
  onHide: function () {
    clearInterval(time1)
    var that = this
    var docindex = that.data.docindex
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    that.setData({
      docindex: docindex
    })
  },
  onUnload() {
    disp.fire("em.chatroom.leave");
    clearInterval(time1)
    var docindex = this.data.docindex
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      docindex: docindex
    })
  },
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    // 停止下拉动作
    wx.hideNavigationBarLoading();
    wx.stopPullDownRefresh();
  },
  //查询患者第一次问诊
  getuserone() {
    var that = this
    if (!that.data.orders) {
      var orders = that.data.back_orser
    } else {
      var orders = that.data.orders
    }
    var id = that.data.id
    var key_words = that.data.key_words
    if (key_words == "tuwenwenzhen") {
      app.util.request({
        'url': 'entry/wxapp/tuwen.oneorder',
        data: {
          openid: that.data.openid,
          id: id
        },
        success: function (res) {
          //console.log(res)
          var key_words = 'tuwenwenzhen'
          var overtime = res.data.overtime
          var ifpay = res.data.ifpay
          that.getSetimout(key_words, overtime, ifpay)
          that.setData({
            oneorder: res.data,
            detail: res.data
          })
        }
      })
    }
    if (key_words == "dianhuajizhen") {
      app.util.request({
        'url': 'entry/wxapp/yuyue.oneorder',
        data: {
          openid: that.data.openid,
          id: id
        },
        success: function (res) {
          console.log(res)
          var key_words = 'dianhuajizhen'
          var overtime = res.data.overtime
          var ifpay = res.data.ifpay
          that.getSetimout(key_words, overtime, ifpay)
          that.setData({
            oneorder: res.data,
            detail: res.data,
          })
        }
      })
    }
    if (key_words == "shipinwenzhen" || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      app.util.request({
        'url': 'entry/wxapp/yuyue.oneorder',
        data: {
          openid: wx.getStorageSync('openid'),
          id: id
        },
        success: function (res) {
          //console.log(res)
          if (key_words == "shipinwenzhen") {
            var key_words = 'shipinwenzhen'
          }
          if (key_words == "tijianjiedu") {
            var key_words = 'tijianjiedu'
          }
          if (key_words == 'shoushukuaiyue') {
            var key_words = 'shoushukuaiyue'
          }
          var overtime = res.data.overtime
          var ifpay = res.data.ifpay
          that.getSetimout(key_words, overtime, ifpay)
          that.setData({
            oneorder: res.data,
            detail: res.data
          })
        }
      })
    }
    if (key_words == "yuanchengkaifang") {
      app.util.request({
        'url': 'entry/wxapp/yuyue.getordercfdetail',
        data: {
          openid: that.data.openid,
          orders: orders
        },
        success: function (res) {
          console.log(res)
          var key_words = 'yuanchengkaifang'
          var overtime = res.data.overtime
          var ifpay = res.data.ifpay
          that.getSetimout(key_words, overtime, ifpay)
          that.setData({
            detail: res.data
          })
        }
      })
    }
    if (key_words == "yuanchengguahao") {
      app.util.request({
        'url': 'entry/wxapp/yuyue.oneorderguahao',
        data: {
          openid: that.data.openid,
          id: id
        },
        success: function (res) {
          //console.log(res)
          var key_words = 'yuanchengguahao'
          var overtime = res.data.overtime
          var ifpay = res.data.ifpay
          that.getSetimout(key_words, overtime, ifpay)
          that.setData({
            oneorder: res.data,
            detail: res.data,
          })
        }
      })
    }
  },
  getSetimout(key_words, overtime, ifpay) {
    var that = this
    var key_words = key_words
    var overtime = parseInt(overtime * 1000)
    var ifpay = ifpay
    var back_orser = that.data.back_orser
    var date1 = new Date(overtime)
    //console.log(date1)
    // time1 = setInterval(function () {
    //   var date = new Date()
    //   var sheyuTime = Date.parse(date1) - Date.parse(date)
    //   let hours = parseInt((sheyuTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    //   let minutes = parseInt((sheyuTime % (1000 * 60 * 60)) / (1000 * 60));
    //   let seconds = (sheyuTime % (1000 * 60)) / 1000;
    //   that.setData({
    //     dumiao: hours + ":" + minutes + ":" + seconds
    //   })

    //   if (sheyuTime == 0 ) {
    //     clearInterval(time1)
    //     app.util.request({
    //       'url': 'entry/wxapp/zhuanjia.dopagetime',
    //       data: {
    //         orders: back_orser,
    //         ifpay: ifpay,
    //         key_words: key_words
    //       },
    //       success: function (res) {
    //         //console.log(res)
    //         wx.showToast({
    //           title: '订单已结束',
    //           icon: 'none',
    //           success: function () {
    //             // setTimeout(function () {
    //             //   wx.navigateBack({
    //             //     detail: 1
    //             //   }, 1500)
    //             // })
    //           }
    //         })
    //       }
    //     })
    //     return false
    //   }
    //   if (sheyuTime <= 0 ) {
    //     clearInterval(time1)
    //     that.setData({
    //       dumiao: "00:00:00"
    //     })
    //     app.util.request({
    //       'url': 'entry/wxapp/zhuanjia.dopagetime',
    //       data: {
    //         orders: back_orser,
    //         ifpay: ifpay,
    //         key_words: key_words
    //       },
    //       success: function (res) {
    //         //console.log(res)
    //       }
    //     })
    //   }
    // }, 1000)

  },
  getOrderlist() {
    var that = this
    var id = that.data.id
    var zid = that.data.zid
    var key_words = that.data.key_words
    var openid = that.data.openid
    var back_orser = that.data.back_orser
    if (key_words == "tuwenwenzhen") {
      app.util.request({
        'url': 'entry/wxapp/tuwen.listall',
        data: {
          openid: openid,
          zid: zid,
          back_orser: back_orser
        },
        success: function (res) {
          var list = res.data
          for (var i = 0; i < list.length; i++) {
            var m, s;
            m = Math.floor(list[i].thtime / 1000 / 60 % 60);
            s = Math.floor(list[i].thtime / 1000 % 60);
            if (m < 10) {
              m = '0' + m
            }
            if (s < 10) {
              s = '0' + s
            }
            list[i].endtime = m + ':' + s
            list[i].play_show = true
            list[i].txt_show = true
            list[i].context = ''
          }
          that.setData({
            list: list
          })
          console.log("list", that.data.list)
        }
      })
    }
    //电话问诊
    if (key_words == "dianhuajizhen" || key_words == "shipinwenzhen" || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      app.util.request({
        'url': 'entry/wxapp/yuyue.alldochuida',
        data: {
          id: id,
          openid: openid,
          zid: zid,
          back_orser: back_orser
        },
        success: function (res) {
          var list = res.data
          for (var i = 0; i < list.length; i++) {
            var m, s;
            m = Math.floor(list[i].thtime / 1000 / 60 % 60);
            s = Math.floor(list[i].thtime / 1000 % 60);
            if (m < 10) {
              m = '0' + m
            }
            if (s < 10) {
              s = '0' + s
            }
            list[i].endtime = m + ':' + s
            list[i].play_show = true
            list[i].txt_show = true
            list[i].context = ''
          }
          that.setData({
            list: list
          })
          console.log("list", that.data.list)
        }
      })
    }
    //处方问诊
    if (key_words == "yuanchengkaifang") {
      if (that.data.openid) {
        var openid = that.data.openid
        var back_orser = that.data.back_orser
      }
      app.util.request({
        'url': 'entry/wxapp/yuyue.cflistalldoc',
        data: {
          id: id,
          zid: zid,
          openid: openid,
          back_orser: back_orser,
          key_words: key_words
        },
        success: function (res) {
          var list = res.data
          for (var i = 0; i < list.length; i++) {
            var m, s;
            m = Math.floor(list[i].thtime / 1000 / 60 % 60);
            s = Math.floor(list[i].thtime / 1000 % 60);
            if (m < 10) {
              m = '0' + m
            }
            if (s < 10) {
              s = '0' + s
            }
            list[i].endtime = m + ':' + s
            list[i].play_show = true
            list[i].txt_show = true
            list[i].context = ''
          }
          that.setData({
            list: list
          })
          console.log("list", that.data.list)
        }
      })

      //查询处方订单
      // app.util.request({
      //   'url': 'entry/wxapp/zhuanjia.chufangcont',
      //   data: {
      //     back_orser: back_orser,
      //     c_id: that.data.id
      //   },
      //   success: function (res) {
      //     console.log(res)
      //     that.setData({
      //       cfdata: res.data
      //     })
      //   }
      // })
    }
    //挂号
    if (key_words == "yuanchengguahao") {
      app.util.request({
        'url': 'entry/wxapp/yuyue.allguahaohuida',
        data: {
          id: id,
          openid: openid,
          zid: zid,
          back_orser: back_orser
        },
        success: function (res) {
          console.log(res)
          var list = res.data
          for (var i = 0; i < list.length; i++) {
            var m, s;
            m = Math.floor(list[i].thtime / 1000 / 60 % 60);
            s = Math.floor(list[i].thtime / 1000 % 60);
            if (m < 10) {
              m = '0' + m
            }
            if (s < 10) {
              s = '0' + s
            }
            list[i].endtime = m + ':' + s
            list[i].play_show = true
            list[i].txt_show = true
            list[i].context = ''
          }
          that.setData({
            list: list
          })
          console.log("list", that.data.list)
        }
      })
    }
  },
  clickshow: function (t) {
    this.setData({
      show: !0,
      hide: !1
    });
  },
  clickshow1: function (t) {
    this.setData({
      show: !1,
      hide: !0
    });
  },
  tabinput2(e) {
    var that = this
    that.setData({
      shouwtab: !this.data.shouwtab
    })
  },
  tabinput(e) {
    var that = this
    var id = that.data.id
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    if (key_words == 'tuwenwenzhen') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.updatetwstate',
        data: {
          back_orser: back_orser
        },
        success: function (res) {
          console.log(res)
          clearInterval(time1)
          //图文问诊接诊
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.tuwenmsgdh',
            data: {
              id: id,
            },
            success: function (res) {
              console.log(res)
            }
          })

          app.util.request({
            'url': 'entry/wxapp/zhuanjia.wxtemplet',
            data: {
              id: id,
              keywords: '图文问诊',
              key_words: 'tuwenwenzhen'
            },
            success: function (res) {
              console.log(res)
            }
          })

          that.setData({
            shouwtab: !this.data.shouwtab
          })
          that.getuserone()
        }
      })
    }
    if (key_words == 'dianhuajizhen' || key_words == 'shipinwenzhen' || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.updatewzstate',
        data: {
          back_orser: back_orser,
        },
        success: function (res) {
          console.log(res)
          clearInterval(time1)
          //问诊接诊
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.dianhuamsgdh',
            data: {
              id: id,
            },
            success: function (res) {
              console.log(res)
            }
          })
          if (key_words == 'dianhuajizhen') {
            var keywords = '电话问诊'
          }
          if (key_words == 'shipinwenzhen') {
            var keywords = '视频问诊'
          }
          if (key_words == 'tijianjiedu') {
            var keywords = '体检解读'
          }
          if (key_words == 'shoushukuaiyue') {
            var keywords = '手术快约'
          }
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.wxtemplet',
            data: {
              id: id,
              keywords: keywords,
              key_words: key_words
            },
            success: function (res) {
              console.log(res)
            }
          })



          if (key_words == 'shipinwenzhen') {
            //视频问诊开始模板提醒
            app.util.request({
              'url': 'entry/wxapp/zhuanjia.mbstrat',
              data: {
                id: id,
              },
              success: function (res) {
                console.log(res)
              }
            })
          }

          that.setData({
            shouwtab: !this.data.shouwtab
          })
          that.getuserone()
        }
      })
    }
    if (key_words == 'yuanchengkaifang') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.updatecfstate',
        data: {
          back_orser: back_orser
        },
        success: function (res) {
          //console.log(res)
          clearInterval(time1)
          //处方接诊
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.kfjzmsgdh',
            data: {
              id: id,
            },
            success: function (res) {
              console.log(res)
            }
          })
          that.setData({
            shouwtab: !this.data.shouwtab
          })
          that.getuserone()
        }
      })
    }
    if (key_words == 'yuanchengguahao') {
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.updateghstate',
        data: {
          back_orser: back_orser,
        },
        success: function (res) {
          console.log(res)
          clearInterval(time1)
          that.setData({
            shouwtab: !this.data.shouwtab
          })
          that.getuserone()
        }
      })
    }
  },
  buttonclick: function () {
    // wx: wx.showActionSheet({
    //   itemList: ['公开问题'],
    //   itemColor: '',
    //   success: function (res) {
    //     //console.log(res);
    //     if (res.tapIndex == 0) {
    //       if (!res.cancel) {
    //         //console.log("跳转");
    //         wx.navigateTo({
    //           url: 'url',
    //         })
    //       }
    //     }
    //   },
    //   fail: function (res) {},
    //   complete: function (res) {},
    // })
  },
  getchar(e) {
    var that = this
    var id = that.data.id
    var zid = that.data.zid
    var typedate = that.data.typedate
    var key_words = that.data.key_words
    var j_id = that.data.j_id
    var list = that.data.list
    var text = list[0].content.text
    var openid = e.currentTarget.dataset.openid
    var back_orser = that.data.back_orser
    var ifzj = 1
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/yishengkaifang/yishengkaifang?id=' + id + '&zid=' + zid + '&typedate=' + typedate + '&key_words=' + key_words + '&zid=' + zid + '&j_id=' + j_id + '&ifzj=1' + '&text=' + text + '&openid=' + openid + '&back_orser=' + back_orser,
    })
  },
  previewImg: function (t) {
    //console.log(t)
    var current = t.target.dataset.src;
    //预览图片
    var imgs = []
    imgs.push(current)
    wx.previewImage({
      current: current,
      urls: imgs,
    });
  },
  twentrec(e) {
    var that = this
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    if (key_words == 'tuwenwenzhen') {
      wx.showModal({
        title: '提示',
        content: '是否接诊',
        success(res) {
          if (res.confirm) {
            app.util.request({
              'url': 'entry/wxapp/zhuanjia.updatetwstate',
              data: {
                back_orser: back_orser
              },
              success: function (res) {
                //console.log(res)
              }
            })
            //console.log('用户点击确定')
          } else if (res.cancel) {
            //console.log('用户点击取消')
          }
        }
      })
    }

  },
  lookreport(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var wzid = that.data.id
    var zid = that.data.zid
    var back_orser = that.data.back_orser
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/diagReport/diagReport?id=' + id + '&ifzj=1&wzid=' + wzid + '&zid=' + zid + '&back_orser=' + back_orser,
    })
  }

});